import mock from "api/mock.js"
import sph from "./sph.js"

// mock数据
export const getBanners = () =>mock.get("/banners")
export const getFloors = () =>mock.get("/floors")
export const getSort = () =>mock.get("/sort")

// 三级分类请求
export const getBaseCategoryList=()=>sph.get("/api/product/getBaseCategoryList")

// search页商品请求
//options:{category1Id,category2Id,category3Id,categoryName,keyword,pageNo,pageSize}
export const getGoodsList=(options)=>sph.post("/api/list",options)

// detail
export const getDetails=(skuId)=>sph.get(`/api/item/${skuId}`)

// 添加到购物车
export const getAddToCart=({skuId,skuNum})=>sph.post(`/api/cart/addToCart/${skuId}/${skuNum}`)

// 获取购物车列表
export const getCartList = ()=>sph.get("/api/cart/cartList")
// 删除购物车商品
export const deleteGoods = (skuId)=>sph.delete(`/api/cart/deleteCart/${skuId}`)
// 切换商品选中状态
export const switchChecked = ({skuID,isChecked})=>sph.get(`/api/cart/checkCart/${skuID}/${isChecked}`)
// 全选全不选
export const switchAll = ({skuIdArr=[],isChecked})=>{
  let arr = []
  skuIdArr.forEach(skuID=>{
    const promise =  switchChecked({skuID,isChecked})
    arr.push(promise)
  })
  return Promise.all(arr)
}

// 登录
// phone
// password
export const getLogin = ({phone,password})=>sph.post('/api/user/passport/login',{phone,password})

// 注册
// phone
// password
// code
// nickName
export const getRegister = ({phone,password,code})=>sph.post("/api/user/passport/register",{phone,password,code})
// 获取验证码
export const getCode = (phone)=>sph.get(`/api/user/passport/sendCode/${phone}`)

// 退出登录
export const loginOut = ()=>sph.get("/api/user/passport/logout")

// 自动登录
export const autoLogin = ()=>sph.get("/api/user/passport/auth/getUserInfo")

// 获取订单列表
export const getOrders = (page,limit)=>sph.get(`/api/order/auth/${page}/${limit}`)

// 获取trade信息
export const getTrade = ()=>sph.get("/api/order/auth/trade")
// 获取订单地址
export const getAddress = ()=>sph.get('/api/user/userAddress/auth/findUserAddressList')
// 提交订单
// consignee          收件人姓名
// consigneeTel       收件人电话
// deliveryAddress    收件地址
// paymentWay         支付方式
// orderComment       订单备注
// orderDetailList    存储多个商品对象的数组
export const commitOrder = (tradeNo,trade)=>sph.post(`/api/order/auth/submitOrder?tradeNo=${tradeNo}`,trade)
// 获取订单支付信息
export const getPay = (orderId)=>sph.get(`/api/payment/weixin/createNative/${orderId}`)
// 查询支付状态请求
export const queryRequest = (orderId)=>sph.get(`/api/payment/weixin/queryPayStatus/${orderId}`)
